import * as actionType from './constant'
import {getTopBanners,getHotRecomends,getNewAlbums,getTopdatas,getArtistList} from 'services/recommend'

const changeTopBannersAction = res => ({
    type : actionType.CHANGE_TOP_BANNERS,
    topBanners : res.banners
})

const ChangeHotRecommends = res => ({
    type : actionType.CHANGE_HOT_RECOMMENDS,
    hotRecommends : res.result
})

const changeNewAlbums = res =>({
    type : actionType.CHANGE_NEW_ALBUMS,
    newAlbums : res.albums
})

const changeUpList = res =>({
    type : actionType.CHANGE_UP_LIST,
    upList : res.playlist
})

const changeNewList = res =>({
    type : actionType.CHANGE_NEW_LIST,
    newList : res.playlist
})

const changeOriginList = res =>({
    type : actionType.CHANGE_ORIGIN_LIST,
    originList : res.playlist
})

const changeSettleSingsAction = (res) => ({
    type: actionType.CHANGE_SETTLE_SONGER,
    settleSings: res.artists
  })

export const getTopBannersAction = () => {
    return dispatch => {
        getTopBanners().then(res=>{
            dispatch(changeTopBannersAction(res));
        })
    }
}

export const getHotRecomendsAction = ()=>{
    return dispatch =>{
        getHotRecomends().then(res=>{
            dispatch(ChangeHotRecommends(res))
        })
    }
}

export const getNewAlbumsAction = (limit,offset)=>{
    return dispatch => {
        getNewAlbums(limit,offset).then(res => {
            dispatch(changeNewAlbums(res));
        })
    }
}

export const getUpListAction = (idx) =>{
    return dispatch => {
        getTopdatas(idx).then(res=>{
            switch(idx){
                case 0:
                    dispatch(changeNewList(res));
                    break;
                case 2:
                    dispatch(changeOriginList(res));
                    break;
                case 3:
                    dispatch(changeUpList(res));
                    break;
                default:
                    break;
            }
        })
    }
}

export const getSettleSingers = () => {
    return dispath => {
      getArtistList(5, 5001).then(res => {
        dispath(changeSettleSingsAction(res))
      })
    }
  }
